<template>
  <div class="product-list-container">
    <div class="hot-header">
      <h2 class="hot-title">{{ title }}</h2>
      <a href="#" class="hot-more">查看更多 ></a>
    </div>
    <div class="product-list-vertical">
      <div class="product-card-vertical" v-for="(product, index) in productList" :key="index">
        <!-- 商品图片区域 -->
        <div class="product-image-container">
          <img :src="product.imgUrl" :alt="product.name" class="product-img-vertical" />
          <!-- 商品标签 -->
          <span 
            class="product-tag-vertical" 
            :class="getTagClass(product.tag)"
            v-if="product.tag"
          >
            {{ product.tag }}
          </span>
        </div>
        
        <!-- 商品信息 -->
        <div class="product-info-vertical">
          <h3 class="product-name-vertical">{{ product.name }}</h3>
          <p class="product-desc-vertical">{{ product.desc }}</p>
          <p class="product-price-vertical">{{ product.price }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps } from 'vue';

// 接收父组件传递的标题和商品数据
const props = defineProps({
  title: {
    type: String,
    default: '热卖推荐'
  },
  productList: {
    type: Array,
    default: () => []
  }
});

// 标签样式类
const getTagClass = (tag) => {
  const tagMap = {
    '新品': 'tag-new',
    '热卖': 'tag-hot',
    '限时': 'tag-time'
  };
  return tagMap[tag] || 'tag-default';
};
</script>

<style scoped>
.product-list-container {
  margin-top: 24px;
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  margin-bottom: 20px; /* 添加底部外边距 */
}

.hot-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f0f0f0;
}

.hot-title {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  margin: 0;
}

.hot-more {
  font-size: 14px;
  color: #999;
  text-decoration: none;
}

.hot-more:hover {
  color: #666;
}

/* 垂直布局的商品列表 */
.product-list-vertical {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.product-card-vertical {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: #fafafa;
  border-radius: 8px;
  transition: all 0.3s ease;
  min-height: 80px; /* 确保卡片有最小高度 */
}

.product-card-vertical:hover {
  background: #f5f5f5;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* 商品图片区域 */
.product-image-container {
  position: relative;
  flex-shrink: 0;
}

.product-img-vertical {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  background: #fff;
  display: block; /* 确保图片正确显示 */
}

/* 商品标签 */
.product-tag-vertical {
  position: absolute;
  top: 4px;
  left: 4px;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  z-index: 1;
}

.tag-new {
  background: #4CAF50;
  color: white;
}

.tag-hot {
  background: #FF9800;
  color: white;
}

.tag-time {
  background: #F44336;
  color: white;
}

.tag-default {
  background: #666;
  color: white;
}

/* 商品信息 */
.product-info-vertical {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 80px; /* 确保信息区域有最小高度 */
}

.product-name-vertical {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin: 0 0 6px 0;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2; /* 修复：添加此行限制显示2行 */
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-desc-vertical {
  font-size: 12px;
  color: #666;
  margin: 0 0 8px 0;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2; /* 修复：添加此行限制显示2行 */
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-price-vertical {
  font-size: 16px;
  color: #ff4444;
  font-weight: bold;
  margin: 0;
}

/* 响应式设计 */
@media (max-width: 375px) {
  .product-list-container {
    padding: 12px;
    margin-top: 16px;
  }
  
  .product-card-vertical {
    padding: 10px;
  }
  
  .product-img-vertical {
    width: 70px;
    height: 70px;
  }
  
  .product-name-vertical {
    font-size: 13px;
  }
  
  .product-desc-vertical {
    font-size: 11px;
  }
  
  .product-price-vertical {
    font-size: 14px;
  }
}
</style>